﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SPIWareMVVM.ViewModels;
using DataAccess;
using System.Windows;

namespace SPIWareMVVM.Views.Commands
{
    public class AddNewProductionCommand : BaseCommand
    {
        public AddNewProductionCommand(BaseViewModel sender) : base(sender) { }

        public override void Execute(object parameter)
        {
            ProductionList list = (ProductionList)parameter;
            if (list != null)
            {
                if (mainWindow == null) mainWindow = (Window1)Window.GetWindow((ProductionList)list);
                ApplicationData.ClearAllExcept(new List<Type> { typeof(MachineProduction) });
                mainWindow.HideLists();

                MachineProduction prod = ApplicationData.NewMachineProduction();
                ApplicationViewModel aVM = (ApplicationViewModel)_sender;

                list.lbProduction.ItemsSource = ApplicationData.ocProduction;
                list.DisplayClosedWO = false;
                list.lbProduction.SelectedItem = prod;

                if (list.Visibility == System.Windows.Visibility.Collapsed) list.Visibility = System.Windows.Visibility.Visible;
            }
        }
    }
}
